package com.application.sistercityapplication.gallery;

import java.util.ArrayList;
import java.util.List;

import ru.truba.touchgallery.GalleryWidget.BasePagerAdapter.OnItemChangeListener;
import ru.truba.touchgallery.GalleryWidget.GalleryViewPager;
import ru.truba.touchgallery.GalleryWidget.UrlPagerAdapter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.application.sistercityapplication.main.MainHomePageViewActivity;
import com.application.sistercityapplication.main.R;

public class FullImageGalleryMainActivity extends Activity {
	String currentPosition;
	private GalleryViewPager mViewPager;
	private List<String> imageList = new ArrayList<String>();

	@Override
	@SuppressWarnings("unchecked")
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_full_image_gallery_main);

		Intent getIntent = getIntent();
		ArrayList<GalleryPhotoItems> list = (ArrayList<GalleryPhotoItems>) getIntent.getSerializableExtra("gallerPhotoList");

		final TextView pageStart = (TextView) findViewById(R.id.pageStart);
		TextView pageAll = (TextView) findViewById(R.id.pageAll);
		TextView closeButt = (TextView) findViewById(R.id.closeText);

		pageStart.setText(getIntent.getStringExtra("currentPosition"));
		pageAll.setText(String.valueOf(list.size() - 1));

		/*
		 * Dump image
		 */
		for (int i = 0; i <= list.size() - 1; i++) {
			imageList.add(list.get(i).getThumbImageURL());
		}

		closeButt.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(FullImageGalleryMainActivity.this,MainHomePageViewActivity.class);
				startActivity(i);
				finish();
			}
		});

		UrlPagerAdapter pagerAdapter = new UrlPagerAdapter(this, imageList);

		pagerAdapter.setOnItemChangeListener(new OnItemChangeListener() {
			@Override
			public void onItemChange(int currentPosition) {
				pageStart.setText(currentPosition + "");
			}
		});

		mViewPager = (GalleryViewPager) findViewById(R.id.viewer);
		mViewPager.setOffscreenPageLimit(3);
		mViewPager.setAdapter(pagerAdapter);
		if (getIntent.getStringExtra("currentPosition").equals("0")) {

		} else {
			mViewPager.setCurrentItem(Integer.parseInt(getIntent.getStringExtra("currentPosition")));
		}
	}
}
